package com.ysj.mall.service.impl;

import cn.hutool.crypto.digest.DigestUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ysj.mall.dao.YsjUserDao;
import com.ysj.mall.entity.YsjUser;
import com.ysj.mall.service.YsjUserService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.sql.Wrapper;
import java.util.Objects;

/**
 * 用户表(YsjUser)表服务实现类
 *
 * @author makejava
 * @since 2024-09-10 14:50:37
 */
@Service("ysjUserService")
public class YsjUserServiceImpl extends ServiceImpl<YsjUserDao, YsjUser> implements YsjUserService {

    @Override
    public YsjUser login(YsjUser user) {
        String usernameReq = user.getUsername();
        String passwordReq = DigestUtil.md5Hex(user.getPassword());

        if (!StringUtils.hasText(usernameReq) || !StringUtils.hasText(passwordReq)) {
            return null;
        }
        LambdaQueryWrapper<YsjUser> warpper = Wrappers.<YsjUser>lambdaQuery()
                .eq(YsjUser::getUsername, usernameReq)
                .eq(YsjUser::getPassword, passwordReq);
        return baseMapper.selectOne(warpper);
    }
}

